#include <iostream>
#include <vector>
using namespace std;

int dp[13][10004];

int coinChange(vector<int>& coins, int amount) {
    for (int j = 0; j <= amount; j++) {
        if (j % coins[0] == 0)
            dp[0][j] = j / coins[0];
        else
            dp[0][j] = -1;
    }

    for (int i = 1; i < coins.size(); i++) {
        for (int j = 0; j <= amount; j++) {
            int step = j / coins[i];
            for (int k = step; k >= 0; k--) {
                if (dp[i - 1][j - k * coins[i]] != -1) {
                    dp[i][j] = dp[i - 1][j - step * coins[i]] + k;
                    break;
                }
            }
            if (dp[i][j] == 0) dp[i][j] = -1;
        }
    }
    return dp[coins.size()-1][amount];
}